﻿using System;
using UnityEngine;

// Token: 0x0200003C RID: 60
public static class HSVUtil
{
	// Token: 0x06000160 RID: 352 RVA: 0x0000DECC File Offset: 0x0000C0CC
	public static HsvColor ConvertRgbToHsv(Color color)
	{
		return HSVUtil.ConvertRgbToHsv((double)((int)(color.r * 255f)), (double)((int)(color.g * 255f)), (double)((int)(color.b * 255f)));
	}

	// Token: 0x06000161 RID: 353 RVA: 0x0000DF00 File Offset: 0x0000C100
	public static HsvColor ConvertRgbToHsv(double r, double b, double g)
	{
		double num = 0.0;
		double num2 = Math.Min(Math.Min(r, g), b);
		double num3 = Math.Max(Math.Max(r, g), b);
		double num4 = num3 - num2;
		double s;
		if (num3.Equals(0.0))
		{
			s = 0.0;
		}
		else
		{
			s = num4 / num3;
		}
		if (s.Equals(0.0))
		{
			num = 360.0;
		}
		else
		{
			if (r.Equals(num3))
			{
				num = (g - b) / num4;
			}
			else if (g.Equals(num3))
			{
				num = 2.0 + (b - r) / num4;
			}
			else if (b.Equals(num3))
			{
				num = 4.0 + (r - g) / num4;
			}
			num *= 60.0;
			if (num <= 0.0)
			{
				num += 360.0;
			}
		}
		return new HsvColor
		{
			H = 360.0 - num,
			S = s,
			V = num3 / 255.0
		};
	}

	// Token: 0x06000162 RID: 354 RVA: 0x0000E040 File Offset: 0x0000C240
	public static Color ConvertHsvToRgb(double h, double s, double v, float alpha)
	{
		double num;
		double num2;
		double num3;
		if (s.Equals(0.0))
		{
			num = v;
			num2 = v;
			num3 = v;
		}
		else
		{
			if (h.Equals(360.0))
			{
				h = 0.0;
			}
			else
			{
				h /= 60.0;
			}
			int num4 = (int)h;
			double num5 = h - (double)num4;
			double num6 = v * (1.0 - s);
			double num7 = v * (1.0 - s * num5);
			double num8 = v * (1.0 - s * (1.0 - num5));
			switch (num4)
			{
			case 0:
				num = v;
				num2 = num8;
				num3 = num6;
				break;
			case 1:
				num = num7;
				num2 = v;
				num3 = num6;
				break;
			case 2:
				num = num6;
				num2 = v;
				num3 = num8;
				break;
			case 3:
				num = num6;
				num2 = num7;
				num3 = v;
				break;
			case 4:
				num = num8;
				num2 = num6;
				num3 = v;
				break;
			default:
				num = v;
				num2 = num6;
				num3 = num7;
				break;
			}
		}
		return new Color((float)num, (float)num2, (float)num3, alpha);
	}
}
